import App from './App'
// import TIM from 'tim-wx-sdk'
import TIM from 'tim-wx-sdk/tim-wx-friendship.js';
import TIMUploadPlugin from 'tim-upload-plugin'
import store from './store';
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
  ...App
})
app.$mount()
// #endif

let tim = TIM.create({SDKAppID: 1600087050})
tim.setLogLevel(1)
tim.registerPlugin({'tim-upload-plugin': TIMUploadPlugin})
tim.on(TIM.EVENT.MESSAGE_RECEIVED, onMessageReceived)
function onMessageReceived(event){
	console.log('messageReceived',event)
	for (let i = 0; i < event.data.length; i++) {
		if (event.data[i].conversationType == 'C2C') {
			uni.$emit('im-page', {
				type: 'MESSAGE',
				data: event.data[i]
			})
			uni.$emit('call-page', {
				type: 'MESSAGE',
				data: event.data[i]
			})
		}
	}
}
// #ifdef VUE3
import { createSSRApp } from 'vue'
import loadings from "@/components/loadings"
export function createApp() {
  const app = createSSRApp(App)
  app.config.globalProperties.$tim = tim
  app.component("loadings",loadings)
  app.use(store)
  return {
    app
  }
}
// #endif